﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ww.wwf.wwfbll;
using ww.lis.lisbll.sam;
using System.Collections;
namespace ww.form.lis.sam.qc
{
    public partial class QC_VarForm : ww.form.wwf.SysBaseForm
    {
        ItemBLL bllItem = new ItemBLL();//项目逻辑        
        string strInstrID = "";//仪器ID
        DataTable dtInstr = new DataTable(); //fjytype_id     
        InstrBLL bllInstr = new InstrBLL();

        public QC_VarForm()
        {
            InitializeComponent();
        }

        private void ItemSetForm_Load(object sender, EventArgs e)
        {
            GetInstrDT();
        }

        /// <summary>
        /// 已经启用的仪器
        /// </summary>
        private void GetInstrDT()
        {
            try
            {
                if (dtInstr.Rows.Count > 0)
                    dtInstr.Clear();
                this.dtInstr = this.bllInstr.BllInstrDTByUseAndGroupID(1, ww.wwf.wwfbll.LoginBLL.strDeptID);//仪器列表

                //this.comboBoxInstr.SelectedIndexChanged -= new EventHandler(comboBoxInstr_SelectedIndexChanged);
                this.comboBoxInstr.DataSource = dtInstr;
            }
            catch (Exception ex)
            {
                WWMessage.MessageShowError(ex.ToString());
            }
        }


        private void comboBoxInstr_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                strInstrID = this.comboBoxInstr.SelectedValue.ToString();
                GetItemDT();
            }
            catch (Exception ex)
            {
                WWMessage.MessageShowError(ex.ToString());
            }
        }

        private void GetItemDT()
        {
            string sql = "SELECT  *  FROM  SAM_ZK_ZKP where 仪器='" + this.strInstrID + "' order by 编号 desc  ";
            this.DataGridViewObject.DataSource = ww.wwf.wwfbll.WWFInit.wwfRemotingDao.DbExecuteDataSetBySqlString(ww.wwf.wwfbll.WWFInit.strDBConn, sql).Tables[0];
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (object.Equals(null, this.DataGridViewObject.CurrentRow)) return;
            try
            {
                if (WWMessage.MessageDialogResult("确认要删除当前记录？"))
                {

                    StringBuilder strSql = new StringBuilder();
                    strSql.Append("delete SAM_ZK_ZKP ");
                    strSql.Append(" where 仪器='" + this.strInstrID + "' and 编号='" + this.DataGridViewObject.CurrentRow.Cells["编号"].Value.ToString() + "' ");
                    WWFInit.wwfRemotingDao.DbExecuteNonQueryBySqlString(WWFInit.strDBConn, strSql.ToString());

                    GetItemDT();
                }
            }
            catch (Exception ex)
            {
                WWMessage.MessageShowWarning(ex.ToString());
            }
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            //if (object.Equals(null, this.DataGridViewObject.CurrentRow)) return;
            QC_VarForm_Item frm = new QC_VarForm_Item(this.strInstrID, this.comboBoxInstr.Text,null);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                GetItemDT();
            }

        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            if (object.Equals(null, this.DataGridViewObject.CurrentRow)) return;

            QC_VarForm_Item frm = new QC_VarForm_Item(this.strInstrID, this.comboBoxInstr.Text, this.DataGridViewObject.CurrentRow);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                GetItemDT();
            }
        }

        private void toolStripButtonR_Click(object sender, EventArgs e)
        {
            GetItemDT();
        }

        private void DataGridViewObject_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            toolStripButton3_Click(null, null);
        }

    }
}